# app/services/user_service.rb
require './app/models/user'

class UserService
  def self.create_user(params)
    User.create(name: params['name'], email: params['email'])
  end

  def self.find_user_by_id(id)
    User.where(id: id).first
  end

  def self.update_user(id, params)
    user = find_user_by_id(id)
    user.update(name: params['name'], email: params['email']) if user
    user
  end

  def self.delete_user(id)
    user = find_user_by_id(id)
    user.destroy if user
    user
  end

  def self.get_all_users
    User.all
  end
end